package com.elvt.server.controller;


import cn.hutool.core.text.StrBuilder;
import com.elvt.server.pojo.Employee;
import com.elvt.server.pojo.EmployeeEc;
import com.elvt.server.service.IEmployeeEcService;
import com.elvt.server.service.IEmployeeService;
import com.elvt.server.utils.RespPageUtil;
import com.elvt.server.utils.RespSult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：elvt
 * @since 2022-05-21
 */
@RestController
@RequestMapping("/personnel/train/ec")
public class EmployeeEcController {
    @Autowired
    private IEmployeeEcService employeeEcService;
    @Autowired
    private IEmployeeService employeeService;
    @ApiOperation(value = "获取所有员工奖惩")
    @GetMapping
    public RespPageUtil findEmpEc(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer size ){
          return employeeEcService.findEmpEc(currentPage, size);
    }
    @ApiOperation(value = "新增员工奖惩")
    @PostMapping
    public RespSult save(@RequestBody EmployeeEc employeeEc){
        if (employeeEcService.save(employeeEc)) {
           return RespSult.success("添加成功！");
        }
        return    RespSult.error("添加失败");
    }
    @ApiOperation(value = "根据id删除员工奖惩")
    @DeleteMapping("/{id}")
    public RespSult deleteByeid(@PathVariable Integer id){
        if (id==null){
            RespSult.error("失败，员工信息位空");
        }
        if (employeeEcService.removeById(id)) {
           return RespSult.success("删除成功！");

        }
         return RespSult.error("删除失败！");

    }
    @ApiOperation(value = "获取所有员工姓名+工号")
    @GetMapping("/emp")
    public List<Employee> findEmpName(){
        List<Employee> list = employeeService.list();
        return  list;
    }
    @ApiOperation(value = "批量删除！")
    @DeleteMapping
    public RespSult deleteByIds(Integer[] ids){
        if (ids==null||ids.length==0){
            return RespSult.error("数据有误");
        }
        if (employeeEcService.removeByIds(Arrays.asList(ids))){
            return RespSult.success("批量删除成功！");
        }
        return RespSult.error("批量删除失败");
    }
}
